namespace QMVnSoft.SystemForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDataLock : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private GBoxControl gBoxControl;
        private TextDate txtNgay_Ks;

        public FormDataLock()
        {
            this.InitializeComponent();
            this.txtNgay_Ks.Value = AppInstance.EndingDateOfSubEnterprice;
            this.Text = AppInstance.SoftwareName;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.OnDo();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDataLock));
            this.gBoxControl = new GBoxControl();
            this.txtNgay_Ks = new TextDate();
            this.btnCancel = new BtnControl();
            this.btnOk = new BtnControl();
            this.gBoxControl.SuspendLayout();
            base.SuspendLayout();
            this.gBoxControl.Controls.Add(this.txtNgay_Ks);
            this.gBoxControl.Font = new Font("Arial", 8.25f);
            this.gBoxControl.Location = new Point(12, 12);
            this.gBoxControl.Name = "gBoxControl";
            this.gBoxControl.Size = new Size(0xfb, 0x4c);
            this.gBoxControl.TabIndex = 0;
            this.gBoxControl.TabStop = false;
            this.gBoxControl.Text = "Khóa sổ ngày";
            this.txtNgay_Ks.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ks.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ks.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ks.Location = new Point(0x56, 30);
            this.txtNgay_Ks.Mask = "00/00/0000";
            this.txtNgay_Ks.Name = "txtNgay_Ks";
            this.txtNgay_Ks.OldValue = null;
            this.txtNgay_Ks.Size = new Size(0x4e, 20);
            this.txtNgay_Ks.TabIndex = 0;
//            this.txtNgay_Ks.Value = null;//manager.GetObject("txtNgay_Ks.Value");
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(140, 0x67);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "&Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(0x3b, 0x67);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x4b, 0x17);
            this.btnOk.TabIndex = 1;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            base.AcceptButton = this.btnOk;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x113, 0x8a);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            base.Controls.Add(this.gBoxControl);
            //base.FormBorderStyle = FormBorderStyle.FixedDialog;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormDataLock";
            base.ShowInTaskbar = false;
            this.gBoxControl.ResumeLayout(false);
            this.gBoxControl.PerformLayout();
            base.ResumeLayout(false);
        }

        private void OnDo()
        {
            AppInstance.EndingDateOfSubEnterprice = (DateTime) this.txtNgay_Ks.Value;
            new CompanyDataAccess().SetEndDate(AppInstance.Subsidiary, AppInstance.EndingDateOfSubEnterprice);
            base.Close();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnDo();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}

